# Generated manually for search functionality
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('schedules', '0006_add_performance_indexes'),
    ]

    operations = [
        migrations.CreateModel(
            name='RouteSearchLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('pol_cd', models.CharField(help_text='搜索的起运港五字码', max_length=10, verbose_name='起运港代码')),
                ('pod_cd', models.CharField(help_text='搜索的目的港五字码', max_length=10, verbose_name='目的港代码')),
                ('search_time', models.DateTimeField(default=django.utils.timezone.now, help_text='用户执行搜索的时间', verbose_name='搜索时间')),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='用户的IP地址', null=True, verbose_name='IP地址')),
                ('user_agent', models.TextField(blank=True, help_text='浏览器用户代理字符串', verbose_name='用户代理')),
                ('results_count', models.IntegerField(default=0, help_text='搜索返回的结果数量', verbose_name='结果数量')),
                ('user', models.ForeignKey(blank=True, help_text='执行搜索的用户，匿名用户可为空', null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='搜索用户')),
            ],
            options={
                'verbose_name': '航线搜索日志',
                'verbose_name_plural': '航线搜索日志',
                'db_table': 'route_search_log',
                'ordering': ['-search_time'],
            },
        ),
        migrations.CreateModel(
            name='PopularRoute',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('pol_cd', models.CharField(max_length=10, verbose_name='起运港代码')),
                ('pod_cd', models.CharField(max_length=10, verbose_name='目的港代码')),
                ('route_name', models.CharField(help_text='显示名称，如"深圳 → 新加坡"', max_length=100, verbose_name='航线名称')),
                ('search_count', models.IntegerField(default=0, help_text='总搜索次数', verbose_name='搜索次数')),
                ('search_count_7d', models.IntegerField(default=0, help_text='最近7天的搜索次数', verbose_name='7天搜索次数')),
                ('search_count_30d', models.IntegerField(default=0, help_text='最近30天的搜索次数', verbose_name='30天搜索次数')),
                ('unique_users_count', models.IntegerField(default=0, help_text='搜索过该航线的唯一用户数', verbose_name='唯一用户数')),
                ('last_search_time', models.DateTimeField(blank=True, null=True, verbose_name='最后搜索时间')),
                ('popularity_score', models.FloatField(default=0.0, help_text='综合热度评分，用于排序', verbose_name='热度评分')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '热门航线',
                'verbose_name_plural': '热门航线',
                'db_table': 'popular_routes',
                'ordering': ['-popularity_score', '-search_count'],
            },
        ),
        migrations.AddIndex(
            model_name='routesearchlog',
            index=models.Index(fields=['pol_cd', 'pod_cd'], name='schedules_r_pol_cd_6b1234_idx'),
        ),
        migrations.AddIndex(
            model_name='routesearchlog',
            index=models.Index(fields=['search_time'], name='schedules_r_search__321abc_idx'),
        ),
        migrations.AddIndex(
            model_name='routesearchlog',
            index=models.Index(fields=['user'], name='schedules_r_user_id_456def_idx'),
        ),
        migrations.AddIndex(
            model_name='popularroute',
            index=models.Index(fields=['popularity_score'], name='schedules_p_popular_789ghi_idx'),
        ),
        migrations.AddIndex(
            model_name='popularroute',
            index=models.Index(fields=['search_count_7d'], name='schedules_p_search__012jkl_idx'),
        ),
        migrations.AddIndex(
            model_name='popularroute',
            index=models.Index(fields=['search_count_30d'], name='schedules_p_search__345mno_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='popularroute',
            unique_together={('pol_cd', 'pod_cd')},
        ),
    ]